package com.xoa.service.BBS.Impl;

import com.xoa.dao.BBS.BbsBoardMapper;
import com.xoa.dao.BBS.BbsCommentMapper;
import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.users.UserExtMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.BBS.BbsBoardWithBLOBs;
import com.xoa.model.BBS.BbsCommentWithBLOBs;
import com.xoa.model.common.SysCode;
import com.xoa.model.sms.SmsBody;
import com.xoa.model.users.UserExt;
import com.xoa.model.users.Users;
import com.xoa.service.BBS.BbsCommentService;
import com.xoa.service.ThreadSerivice.ThreadService;
import com.xoa.service.sms.SmsService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.DateFormat;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class BbsCommentSerciceImpl implements BbsCommentService {

    @Autowired
    BbsCommentMapper bbsCommentMapper;

    @Autowired
    BbsBoardMapper bbsBoardMapper;

    @Autowired
    DepartmentMapper departmentMapper;

    @Autowired
    UsersMapper usersMapper;

    @Autowired
    UserExtMapper userExtMapper;
    @Resource
    private SmsService smsService;
    @Resource
    ThreadPoolTaskExecutor threadPoolTaskExecutor;
    @Resource
    private SysCodeMapper sysCodeMapper;
    @Resource
    private HttpServletRequest request;

    /**
     * 添加讨论区内容
     * @param record
     * @return
     */
    @Override
    public ToJson insertSelective(HttpServletRequest request,BbsCommentWithBLOBs record) {
        ToJson toJson = new ToJson(1,"err");
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
        try {
            record.setUserId(users.getUserId()); //发帖人
            record.setSubmitTime(new Date()); //发布时间
            record.setOldSubmitTime(new Date()); //原始发帖时间
            record.setUpdateTime(new Date()); //修改时间
            record.setFromUser(users.getUserId()); //发信人
            record.setReadeder(""); //阅读者
            record.setUpdatePerson(""); //修改人
            if(record.getBoardId()!=null && record.getBoardId()==-1) {
                record.setType("无分类"); //帖子类别
            }
            //发公告
            int i = bbsCommentMapper.insertSelective(record);
            if(i > 0){
                //事务提醒
                if (!StringUtils.checkNull(record.getToIdStr1())){
                    if (record.getToIdStr1().equals("ALL")){
                        //提醒全部有权限人员
                        BbsBoardWithBLOBs bbsBoardWithBLOBs = bbsBoardMapper.selectByPrimaryKey(record.getBoardId());
                        if (bbsBoardWithBLOBs!=null && (!StringUtils.checkNull(bbsBoardWithBLOBs.getDeptId()) || !StringUtils.checkNull(bbsBoardWithBLOBs.getPrivId()) || !StringUtils.checkNull(bbsBoardWithBLOBs.getUserId()))){
                            Map map=new HashMap();
                            if (!bbsBoardWithBLOBs.getDeptId().equals("ALL_DEPT")){
                                String[] deptId = bbsBoardWithBLOBs.getDeptId().split(",");
                                String[] prlitId = bbsBoardWithBLOBs.getPrivId().split(",");
                                String[] userId = bbsBoardWithBLOBs.getUserId().split(",");
                                map.put("deptIds",deptId);
                                map.put("userPrivs",prlitId);
                                map.put("userIds",userId);
                            }
                            String groupConcatUserId = usersMapper.getGroupConcatUserId(map);
                            record.setToIdStr1(groupConcatUserId!=null ? groupConcatUserId : "");
                        }
                    }
                    this.addAffairs(record,record.getBoardId(),record.getToIdStr1(),request);
                }
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return toJson;
    }

    /**
     * 修改讨论区内容
     * @param record
     * @return
     */
    @Override
    public ToJson updateByPrimaryKeySelective(HttpServletRequest request,BbsCommentWithBLOBs record) {
        ToJson toJson = new ToJson(1,"err");
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
        try{
            record.setUpdatePerson(users.getUserId());
            record.setUpdateTime(new Date());
            int i = bbsCommentMapper.updateByPrimaryKeySelective(record);
            if(i > 0){
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }
        }catch (Exception e){
            e.printStackTrace();
            toJson.setFlag(1);
            toJson.setMsg("err");
        }
        return toJson;
    }
    /**
     * 删除讨论区内容
     * @param commentIds
     * @return
     */
    @Override
    public ToJson deleteAnyById(Integer[] commentIds) {
        ToJson toJson = new ToJson(1,"err");
        try{
            int i = bbsCommentMapper.deleteAnyById(commentIds);
            if(i > 0){
                bbsCommentMapper.deleteByParent(commentIds);
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    @Override
    public ToJson selLastPublicPerson(int boardId) {
        ToJson toJson = new ToJson(1,"err");
        try{
            BbsCommentWithBLOBs bbsCommentWithBLOBs = bbsCommentMapper.selLastPublicPerson(boardId);
            if(bbsCommentWithBLOBs != null){
                toJson.setMsg("ok");
                toJson.setFlag(0);
                toJson.setObject(bbsCommentWithBLOBs);
            }
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 查询讨论区中的主题
     * @param boardId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public ToJson selAllCommentById(Integer boardId,Integer page,Integer limit) {
        ToJson toJson = new ToJson(1,"err");
        Map map = new HashMap();
        try {
            //分页
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(limit);
            pageParams.setUseFlag(true);
            map.put("pageParams", pageParams);
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        try{
            BbsBoardWithBLOBs bbsBoardWithBLOBs = bbsBoardMapper.selectByPrimaryKey(boardId);
            if(bbsBoardWithBLOBs.getBbsRecordSeeYn().equals("1")){//仅本人和版主有权限查看
                Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
                Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
                boolean flag = Arrays.asList(bbsBoardWithBLOBs.getBoardHoster().split(",")).contains(user.getUserId());
                if(flag){
                    map.put("userId",null);
                }else{
                    map.put("userId",user.getUserId());
                }
            }else{
                map.put("userId",null);
            }
            map.put("boardId",boardId);
           List<BbsCommentWithBLOBs> list = bbsCommentMapper.selAllCommentById(map);
           for(BbsCommentWithBLOBs bbsCommentWithBLOBs:list){
               //作者和部门
               if (!StringUtils.checkNull(bbsCommentWithBLOBs.getUserId())){
                   String userId = bbsCommentWithBLOBs.getUserId();
                   Users users = usersMapper.getUsersByuserId(userId);
                   if(users != null){
                       //用户
                       bbsCommentWithBLOBs.setTrueName(users.getUserName());
                       bbsCommentWithBLOBs.setDeptName(departmentMapper.getDeptNameByDeptId(users.getDeptId()));
                   }else{
                       bbsCommentWithBLOBs.setDeptName("未知部门");
                       bbsCommentWithBLOBs.setTrueName("未知用户");
                   }
               }

                //字节数
                if(!StringUtils.checkNull(bbsCommentWithBLOBs.getContent())){
                    String content = bbsCommentWithBLOBs.getContent();
                    byte[]bytes = content.getBytes();
                    bbsCommentWithBLOBs.setTextNums(bytes.length);
                }else{
                    bbsCommentWithBLOBs.setTextNums(0);
                }

               //最后回复
               BbsCommentWithBLOBs bcw = bbsCommentMapper.selLastPublicPersonByParent(bbsCommentWithBLOBs.getCommentId());
               if(bcw != null){
                   Date submitTime = bcw.getSubmitTime();
                   String strDate = DateFormat.getStrDate(submitTime);
                   bbsCommentWithBLOBs.setLastReply(strDate+" by "+bcw.getUserName());
               }else{
                   String strDate = DateFormat.getStrDate(bbsCommentWithBLOBs.getSubmitTime());
                   bbsCommentWithBLOBs.setLastReply(strDate+" by "+bbsCommentWithBLOBs.getAuthorName());
               }
           }

            toJson.setMsg("ok");
            toJson.setFlag(0);
            toJson.setObj(list);
            PageParams pageParams=(PageParams)map.get("pageParams");
            toJson.setTotleNum(pageParams.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }


    /**
     * 查询讨论区帖子审核
     * @param boardId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public ToJson selReview(HttpServletRequest request,Integer boardId,Integer page,Integer limit) {
        ToJson toJson = new ToJson(1,"err");
        Map map = new HashMap();
        try {
            //分页
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(limit);
            pageParams.setUseFlag(true);
            map.put("pageParams", pageParams);
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        try{
           /* Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
            map.put("userId",users.getUserId());*/
            //通过当前登陆人查找父级文章的版主

            map.put("boardId",boardId);
           List<BbsCommentWithBLOBs> list = bbsCommentMapper.selReview(map);
           for(BbsCommentWithBLOBs bbsCommentWithBLOBs:list){
               //作者和部门
               if (!StringUtils.checkNull(bbsCommentWithBLOBs.getUserId())){
                   String userId = bbsCommentWithBLOBs.getUserId();
                   Users users = usersMapper.getUsersByuserId(userId);
                   if(users != null){
                       //用户
                       bbsCommentWithBLOBs.setTrueName(users.getUserName());
                       bbsCommentWithBLOBs.setDeptName(departmentMapper.getDeptNameByDeptId(users.getDeptId()));
                   }else{
                       bbsCommentWithBLOBs.setDeptName("未知部门");
                       bbsCommentWithBLOBs.setTrueName("未知用户");
                   }
               }

                //字节数
                if(!StringUtils.checkNull(bbsCommentWithBLOBs.getContent())){
                    String content = bbsCommentWithBLOBs.getContent();
                    byte[]bytes = content.getBytes();
                    bbsCommentWithBLOBs.setTextNums(bytes.length);
                }else{
                    bbsCommentWithBLOBs.setTextNums(0);
                }


           }
            toJson.setMsg("ok");
            toJson.setFlag(0);
            toJson.setObject(list);
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 讨论区搜索功能
     * @param record
     * @return
     */
    @Override
    public ToJson selByCon(BbsCommentWithBLOBs record) {
        ToJson toJson = new ToJson();
        try {
            //判断当输入的时间起始或结束时间某一栏为空时给与默认值
            if(record.getStartSubmitTime() == null){
                record.setStartSubmitTime("0000-00-00");
            }
            if(record.getEndSubmitTime() == null){
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date date = new Date();
                record.setEndSubmitTime(sdf.format(date));
            }
            //添加查看权限
            BbsBoardWithBLOBs bbsBoardWithBLOBs = bbsBoardMapper.selectByPrimaryKey(record.getBoardId());
            if(bbsBoardWithBLOBs.getBbsRecordSeeYn().equals("1")){//仅本人和版主有权限查看
                Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
                Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
                boolean flag = Arrays.asList(bbsBoardWithBLOBs.getBoardHoster().split(",")).contains(user.getUserId());
                if(!flag){
                    record.setUserId(user.getUserId());
                }
            }
            List<BbsCommentWithBLOBs> list = bbsCommentMapper.selByCon(record);

            for(BbsCommentWithBLOBs bbsCommentWithBLOBs:list){
                //字节数
                if(bbsCommentWithBLOBs.getContent() != null){
                    String content = bbsCommentWithBLOBs.getContent();
                    byte[]bytes = content.getBytes();
                    bbsCommentWithBLOBs.setTextNums(bytes.length);
                }else{
                    bbsCommentWithBLOBs.setTextNums(0);
                }
                //真实姓名
               String userName = usersMapper.getUsernameByUserId(bbsCommentWithBLOBs.getUserId());
                if(userName != null){
                    bbsCommentWithBLOBs.setTrueName(userName);
                }else{
                    bbsCommentWithBLOBs.setTrueName("未知");
                }
            }
            if(list != null){
                toJson.setFlag(0);
                toJson.setMsg("ok");
                toJson.setObj(list);
            }
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("err");
            toJson.setFlag(1);
        }

        return toJson;
    }

    /**
     * 积分榜
     * @return
     */
    @Override
    public ToJson selTextNums() {
        ToJson toJson = new ToJson();
        try{
            List<BbsCommentWithBLOBs> list = bbsCommentMapper.selTextNums();
            for(BbsCommentWithBLOBs bbsCommentWithBLOBs:list){
                String userId = bbsCommentWithBLOBs.getUserId();
                int textNums = bbsCommentWithBLOBs.getTextNums();
                String userName = usersMapper.getUsernameByUserId(userId);
                UserExt userExt = new UserExt();
                userExt.setUserId(userId);
                userExt.setBbsCounter(textNums);
                userExtMapper.updateUserExtByUid(userExt);
                if(userName != null){
                    bbsCommentWithBLOBs.setTrueName(userName);
                }else{
                    bbsCommentWithBLOBs.setTrueName("");
                }
            }
            if(list != null){
                toJson.setFlag(0);
                toJson.setMsg("ok");
                toJson.setObj(list);
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 删除单个回复
     * @param
     * @return
     */
    @Override
    public ToJson deleteByParent(Integer[] parent) {
        return null;
    }

    /**
     * 删除单个回复
     * @param
     * @return
     */
    @Override
    public ToJson deleteByPrimaryKey(Integer commentId){
        ToJson toJson = new ToJson();
        try{
            int count = bbsCommentMapper.deleteByPrimaryKey(commentId);
            if(count >= 0){
                toJson.setFlag(0);
                toJson.setMsg("ok");
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 查询热门文章
     * @return
     */
    @Override
    public ToJson selHotPost() {
        ToJson toJson = new ToJson(1,"err");
        try{
            List<BbsCommentWithBLOBs> list = bbsCommentMapper.selHotPost();
            for(BbsCommentWithBLOBs bbsCommentWithBLOBs:list){
                //字节数
                if(bbsCommentWithBLOBs.getContent() != null){
                    String content = bbsCommentWithBLOBs.getContent();
                    byte[]bytes = content.getBytes();
                    bbsCommentWithBLOBs.setTextNums(bytes.length);
                }else{
                    bbsCommentWithBLOBs.setTextNums(0);
                }
                //真实姓名
                String userName = usersMapper.getUsernameByUserId(bbsCommentWithBLOBs.getUserId());
                if(userName != null){
                    bbsCommentWithBLOBs.setTrueName(userName);
                }else{
                    bbsCommentWithBLOBs.setTrueName("未知");
                }
            }
            if(list != null){
                toJson.setFlag(0);
                toJson.setMsg("ok");
                toJson.setObj(list);
            }

        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 转移主题
     * @return
     */
    @Override
    public ToJson findTransfer(Integer boardId) {
        ToJson toJson=new ToJson(1,"err");
        try {
            toJson.setFlag(0);
            toJson.setMsg("ok");
            toJson.setObj(bbsCommentMapper.findTransfer(boardId));
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 批量修改审批状态
     * @param request
     * @param ids
     * @param isCheck
     * @return
     */
    @Override
    public ToJson updatebatch(HttpServletRequest request, Integer[] ids, Integer isCheck) {
        ToJson toJson=new ToJson(1,"err");
        try {
            int  i=bbsCommentMapper.updateBatch(ids,isCheck);
            if (i>0){
                toJson.setFlag(0);
                toJson.setMsg("ok");
            }
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    //批量修改状态
    @Override
    public ToJson updatefine(HttpServletRequest request, String[] ids, String field, String status) {
        ToJson toJson=new ToJson(1,"err");
        try {
            int  i=bbsCommentMapper.updatefine(ids,field,status);
            if (i>0){
                toJson.setFlag(0);
                toJson.setMsg("ok");
            }
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    //查询文章父级和子级
    @Override
    public ToJson selectById(HttpServletRequest request, Integer id) {
        ToJson toJson=new ToJson(1,"err");
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
        try {
            BbsCommentWithBLOBs primaryKey = bbsCommentMapper.selectByPrimaryKey(id);
            if (primaryKey!=null && primaryKey.getReadCont()!=null  && !StringUtils.checkNull(primaryKey.getReadeder())){
                //修改阅读量
                BbsCommentWithBLOBs bbsComment=new BbsCommentWithBLOBs();
                bbsComment.setCommentId(primaryKey.getCommentId()); //ID
                bbsComment.setReadCont(primaryKey.getReadCont()+1); //阅读数量

                String[] split = primaryKey.getReadeder().split(","); //阅读人
                if (!Arrays.asList(split).contains(users.getUserId())){
                    bbsComment.setReadeder(primaryKey.getReadeder()+users.getUserId()+",");
                }
                bbsCommentMapper.updateById(bbsComment);
            }

            Map map=new HashMap();
            map.put("Child",bbsCommentMapper.selectByChild(id));
            map.put("Thislevel",primaryKey);
            toJson.setFlag(0);
            toJson.setMsg("ok");
            toJson.setObject(map);
        }catch (Exception e){
            e.getMessage();
        }
        return toJson;
    }

    //转移主题接口
    @Override
    public ToJson updateTransfer(Integer[] commentId, Integer boardId) {
        ToJson toJson=new ToJson(1,"err");
        try {
            Map map=new HashMap();
            map.put("field1","BOARD_ID");
            map.put("status1",boardId);

            map.put("field2","COMMENT_ID");
            map.put("status2",commentId);
            int i = bbsCommentMapper.updateTransfer(map);
            if (i>0){
                map.clear();
                map.put("field1","BOARD_ID");
                map.put("status1",boardId);

                map.put("field2","PARENT");
                map.put("status2",commentId);
                bbsCommentMapper.updateTransfer(map);

                toJson.setFlag(0);
                toJson.setMsg("ok");
            }
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 查询单个帖子的内容
     * @param commentId
     * @return
     */
    @Override
    public ToJson selContentAndReply(HttpServletRequest request,Integer commentId){
        ToJson toJson = new ToJson();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
        try{
            List<BbsCommentWithBLOBs> list = bbsCommentMapper.selContentAndReply(commentId);
            if(list != null && list.size() > 0){
                int cId = 0;
                for(BbsCommentWithBLOBs bbsCommentWithBLOBs:list){
                        //每执行以此此方法，使阅读数量加1
                        if(bbsCommentWithBLOBs.getParent() == 0){
                            BbsCommentWithBLOBs record = new BbsCommentWithBLOBs();
                            cId = bbsCommentWithBLOBs.getCommentId();
                            int readCont = bbsCommentWithBLOBs.getReadCont() + 1;
                            record.setCommentId(cId);
                            record.setReadCont(readCont);
                            int count = bbsCommentMapper.updateById(record);
                        }else{
                            BbsCommentWithBLOBs record = new BbsCommentWithBLOBs();
                            //回复人数
                            int id = bbsCommentWithBLOBs.getParent();
                            int count = bbsCommentMapper.selParentCount(id);
                            record.setCommentId(cId);
                            record.setReplyCont(count);
                            bbsCommentMapper.updateById(record);
                        }
                        //判断署名标记
                        String userId = bbsCommentWithBLOBs.getUserId();
                        String userName = usersMapper.getUsernameById(userId);
                        String trueName = (bbsCommentWithBLOBs.getAuthorNameTmep()==1)?userName:bbsCommentWithBLOBs.getNickName();
                        bbsCommentWithBLOBs.setTrueName(trueName);

                        //将查阅人的ID存放进数据库
                        String uId = users.getUserId();
                        String reader = bbsCommentWithBLOBs.getReadeder();
                        String readerArr[] = reader.split(",");
                        StringBuffer sb = new StringBuffer();
                        Boolean flag = true;
                        for(int i = 0;i < readerArr.length;i++){
                            if(!"".equals(readerArr[i])){
                                if(uId.equals(readerArr[i])){
                                    sb.append(uId+",");
                                    flag = false;
                                }else{
                                    sb.append(readerArr[i] + ",");
                                }
                            }
                        }
                        if(flag){
                           sb.append(uId + ",");
                        }

                        BbsCommentWithBLOBs record = new BbsCommentWithBLOBs();
                        record.setCommentId(cId);
                        record.setReadeder(sb.toString());
                        bbsCommentMapper.updateById(record);

                }
                toJson.setFlag(0);
                toJson.setMsg("ok");
                toJson.setObj(list);
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }

        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }



    /**
     * 给讨论区设置添加提醒事务
     *
     * @param todoId 收信人（用，号拼接）
     */
    @Async
    public void addAffairs(BbsCommentWithBLOBs bbsCommentWithBLOBs, final Integer boardId, final String todoId, HttpServletRequest request) {
        final String sqlType = (String) request.getSession().getAttribute("loginDateSouse");
        final String userName = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserName();
        final BbsCommentWithBLOBs bbsBoardf = bbsCommentWithBLOBs;
        final String remind = request.getParameter("remind");
        final String smsRemind = request.getParameter("smsRemind");
        this.threadPoolTaskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                ContextHolder.setConsumerType("xoa" + sqlType);
                SmsBody smsBody = new SmsBody();
                smsBody.setFromId(bbsBoardf.getFromUser());
                smsBody.setContent("讨论区发帖！主题：" + bbsBoardf.getSubject());
                Date date = new Date();
                long dateLong = date.getTime()/1000;
                String strDate = String.valueOf(dateLong);
                Integer dateInt = Integer.valueOf(strDate.trim());
                smsBody.setSendTime(dateInt);
                SysCode sysCode = new SysCode();
                sysCode.setCodeName("内部讨论区");
                sysCode.setParentNo("SMS_REMIND");
                SysCode codeNoByNameAndParentNo = sysCodeMapper.getCodeNoByNameAndParentNo(sysCode);
                if (codeNoByNameAndParentNo != null) {
                    smsBody.setSmsType(codeNoByNameAndParentNo.getCodeNo());
                }
                if (!StringUtils.checkNull(bbsBoardf.getAttachmentId()) && !StringUtils.checkNull(bbsBoardf.getAttachmentName())) {
                    smsBody.setIsAttach("1");
                }
                smsBody.setRemindUrl("/bbs/theme?boardId=" + boardId);
                String title = userName + "：新建帖子！";
                String context = "主题:" + bbsBoardf.getSubject();
                smsService.saveSms(smsBody, todoId, remind, smsRemind, title, context, sqlType);
            }
        });

    }
}
